package impl;

import dao.RoleDao;
import domain.Role;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description: 角色数据的操作实现
 */
public class RoleDaoImpl implements RoleDao {

    @Override
    public void addRole(Role role) {
        Connection connection = null;
        PreparedStatement statement = null;
        try {
            connection = DBUtil.getConnection();
            String sql = "insert into role values (null, ?, ?, ?)";
            statement =connection.prepareStatement(sql);
            statement.setString(1, role.getName());
            statement.setInt(2, role.getState());
            statement.setString(3, role.getRemark());
            statement.executeUpdate();
        }catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            DBUtil.close(connection, statement, null);
        }
    }

    @Override
    public void deleteRole(int id) {

    }

    @Override
    public void updateRole(Role role) {

    }

    @Override
    public Role selectRole(int id) {
        return null;
    }
}
